package cn.whale.basic.utils;

import lombok.Data;

import java.util.HashMap;

//Ajax请求响应对象的类
@Data
public class JSONResult  {
    //结果状态
    private boolean success = true;
    //响应吗
    private Integer code = 0;
    //响应信息
    private String message = "操作成功!";
    //响应对象
    private Object data;

    public  static JSONResult success(){
        return new JSONResult();
    }
    public  static JSONResult success(String message){
        JSONResult jsonResult = success();
        jsonResult.setMessage(message);
        return jsonResult;
    }
    public  static JSONResult success(Object data){
        JSONResult jsonResult = success();
        jsonResult.setData(data);
        return jsonResult;
    }
    public  static JSONResult success(String message , Object data){
        JSONResult jSONResult = success(data);
        jSONResult.setMessage(message);
        return jSONResult;
    }

    public  static JSONResult error(String message , Object data){
        JSONResult jSONResult = success(message,data);
        jSONResult.setSuccess(false);
        return jSONResult;
    }
    public  static JSONResult error(Object data){
        JSONResult jSONResult = success(data);
        jSONResult.setSuccess(false);
        return jSONResult;
    }
    public  static JSONResult error(String message){
        JSONResult jSONResult = success(message);
        jSONResult.setSuccess(false);
        return jSONResult;
    }
    public  static JSONResult error(){
        JSONResult jSONResult = success();
        jSONResult.setSuccess(false);
        return jSONResult;
    }

}
